<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class JudicialOfficersInfoRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'tel' => Rule::unique('judicial_officers_infos')->where(function ($query) {
                $query->where('id', '!=', $this->id);
            }),
            'code' => Rule::unique('judicial_officers_infos')->where(function ($query) {
                $query->where('id', '!=', $this->id);
            }),
            'username' => Rule::unique('users')->where(function ($query) {
                $query->where('id', '!=', $this->users_id);
            }),
        ];
    }

    public function messages()
    {
        return [
            'tel.unique' => '手机号重复',
            'code.unique'=>'用户编号重复',
            'username.unique'=>'用户名重复'
        ];
    }
}
